<?php
namespace app\index\validate;
use think\Validate;
class Login extends Validate
{
    protected $rule = [
        'tel' => 'check_phone',
        'pass' => 'require',
        'reg_com' => 'require',
        'reg_dept' => 'require',
        'reg_name' => 'require',
        'code' => 'require',
    ];

    protected $message = [
        'tel.check_phone' => '请输入有效手机号码',
        'pass.require' => '请输入登录密码',
        'reg_com.require' => '请输入公司名称',
        'reg_dept.require' => '请输入部门',
        'reg_name.require' => '请输入姓名',
        'code.require' => '请输入验证码',
    ];

    protected $scene = [
        'check_tel' => ['tel'],
        'login_pass' => ['tel','pass'],
        'login_code' => ['tel','code'],
        'reg' => ['reg_com','reg_dept','reg_name','tel','code','pass']
    ];

    protected function check_phone($value, $rule, $data = [], $name, $description)
    {
        if (strlen($value) != 11) {
            return false;
        }
        $res = preg_match("/^[1][3,4,5,6,7,8,9][0-9]{9}$/", $value, $matches);
        if (!$res) {
            return false;
        }
        return true;
    }
}